package com.taobao.txc.resourcemanager;

import com.taobao.txc.a.b.g;
import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.a;
import com.taobao.txc.common.b.c;
import com.taobao.txc.common.c.B;
import com.taobao.txc.common.c.r;
import com.taobao.txc.common.c.s;
import com.taobao.txc.common.j;
import com.taobao.txc.resourcemanager.a.a.d;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import sun.misc.Signal;

public class k
  extends i
{
  private static final LoggerWrap a = LoggerInit.logger;
  private static Map<String, q> b = new ConcurrentHashMap();
  private static List<com.taobao.txc.common.b> c = Collections.synchronizedList(new ArrayList());
  private static ScheduledExecutorService d = Executors.newScheduledThreadPool(1);
  private d e = null;
  private static ScheduledExecutorService f = Executors.newSingleThreadScheduledExecutor();
  private static ExecutorService g = Executors.newSingleThreadExecutor();
  private static int h = 7200;
  
  public static k c()
  {
    return (k)i.a("at");
  }
  
  private Integer i()
  {
    String str = g.f();
    return com.taobao.txc.common.config.o.a().c(str);
  }
  
  public void d()
  {
    try
    {
      d.scheduleAtFixedRate(new l(this), 10L, 1000L, TimeUnit.MILLISECONDS);
      try
      {
        Signal.handle(new Signal("USR2"), new m(this));
      }
      catch (Exception localException1)
      {
        a.warn(String.format("current OS not support signal USR2", new Object[] { localException1 }));
      }
      f.scheduleAtFixedRate(new o(this), 60L, h, TimeUnit.SECONDS);
    }
    catch (Exception localException2)
    {
      throw c.a(localException2);
    }
  }
  
  private void b(Integer paramInteger)
  {
    if (this.e != null) {
      try
      {
        this.e.a(paramInteger);
        a.info("clean old txclog success.");
      }
      catch (Exception localException)
      {
        a.error("", "clean old txclog fail. " + localException.getMessage());
      }
    }
  }
  
  public void a(String paramString1, long paramLong, String paramString2, String paramString3, byte paramByte, String paramString4)
  {
    String str = j.a(paramString1, paramLong);
    if (b.containsKey(str)) {
      throw new c("Branch is working:" + b.get(str));
    }
    if ((paramByte != a.c.a()) && (c.size() >= 10000)) {
      return;
    }
    if (b.put(str, q.a) != null) {
      throw new c("Branch is working:" + b.get(str));
    }
    try
    {
      com.taobao.txc.common.b localb = new com.taobao.txc.common.b(paramString1, paramLong, paramString2, paramString3, paramByte, paramString4, 0);
      switch (p.a[localb.c().ordinal()])
      {
      case 1: 
      case 2: 
        c.add(localb);
        break;
      case 3: 
        e().a(localb);
      }
    }
    catch (SQLException localSQLException)
    {
      throw c.a(localSQLException);
    }
    finally
    {
      b.remove(str);
    }
  }
  
  public void a(String paramString1, long paramLong, String paramString2, String paramString3, byte paramByte, int paramInt)
  {
    String str = j.a(paramString1, paramLong);
    if (b.containsKey(str)) {
      throw new c("Branch is working:" + b.get(str));
    }
    if (b.put(str, q.b) != null) {
      throw new c("Branch is working:" + b.get(str));
    }
    com.taobao.txc.common.b localb = new com.taobao.txc.common.b(paramString1, paramLong, paramString2, paramString3, paramByte, null, paramInt);
    try
    {
      e().b(localb);
    }
    catch (Exception localException)
    {
      throw c.a(localException);
    }
    finally
    {
      b.remove(str);
    }
  }
  
  public void a(String paramString1, long paramLong, String paramString2, String paramString3, byte paramByte) {}
  
  public void a(String paramString1, long paramLong, String paramString2)
  {
    r localr = new r();
    localr.b(paramString2.toUpperCase());
    localr.a(paramString1);
    localr.a(paramLong);
    try
    {
      s locals = (s)b().a(localr, 30000L);
      if (locals.a() != B.a.a()) {
        throw new c(locals.a(), locals.b());
      }
    }
    catch (Throwable localThrowable)
    {
      localThrowable = localThrowable;
      throw c.a(localThrowable);
    }
    finally {}
  }
  
  public d e()
  {
    return this.e;
  }
  
  public void a(d paramd)
  {
    this.e = paramd;
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.resourcemanager.k
 * JD-Core Version:    0.7.0.1
 */